<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="UTF-8" />
    <title>Loading - isOpen</title>
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
    />
    <link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
    <link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
    <script src="../../../../../scripts/testing/scripts.js"></script>
    <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
    <style>
      .grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        grid-row-gap: 20px;
        grid-column-gap: 20px;
      }

      .grid-item {
        margin: 0 auto;
      }

      h2 {
        font-size: 12px;
        font-weight: normal;

        color: #6f7378;

        margin-top: 10px;
        margin-left: 5px;
      }
    </style>
  </head>

  <body>
    <ion-app>
      <ion-header>
        <ion-toolbar>
          <ion-title>Loading - isOpen</ion-title>
        </ion-toolbar>
      </ion-header>

      <ion-content class="ion-padding">
        <div class="grid">
          <div class="grid-item">
            <h2>Default</h2>
            <button id="default" onclick="openLoading()">Open Loading</button>
          </div>
          <div class="grid-item">
            <h2>Open, then close after 500ms</h2>
            <button id="timeout" onclick="openLoading(500)">Open Loading</button>
          </div>
        </div>

        <ion-loading message="Hello world"></ion-loading>
      </ion-content>
    </ion-app>

    <script>
      const loading = document.querySelector('ion-loading');

      const openLoading = (timeout) => {
        loading.isOpen = true;

        if (timeout) {
          setTimeout(() => {
            loading.isOpen = false;
          }, timeout);
        }
      };

      loading.addEventListener('ionLoadingDidDismiss', () => {
        loading.isOpen = false;
      });
    </script>
  </body>
</html>
